package com.sunday.haowushop.ui.mine.details;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.sunday.common.adapter.MainFragmentPagerAdapter;
import com.sunday.common.base.BaseActivity;
import com.sunday.haowushop.R;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by 刘涛 on 2017/8/1.
 */

public class BalanceExtraDetailActivity extends BaseActivity {

    @Bind(R.id.title_view)
    TextView titleView;
    @Bind(R.id.tab_layout)
    TabLayout tabLayout;
    @Bind(R.id.view_pager)
    ViewPager viewPager;

    private int type = 1;//类型(1-优惠券 2-云币)
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_list);
        ButterKnife.bind(this);
        titleView.setText("账户明细");
        initFragment();
    }


    private void initFragment() {
        fragments.add(BalanceListFragment.newInstance(1));//余额
        fragments.add(BalanceListFragment.newInstance(2));//服务费
        viewPager.setAdapter(new MainFragmentPagerAdapter(getSupportFragmentManager(), mContext,
                fragments, R.array.balance_title));
        viewPager.setOffscreenPageLimit(2);
        tabLayout.setupWithViewPager(viewPager);
        int page = getIntent().getIntExtra("page", 0);
        viewPager.setCurrentItem(page, false);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                ((BalanceListFragment) fragments.get(position)).refresh();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


}
